package animation.model;


/**
 * Created by IntelliJ IDEA.
 * User: emilio
 * Date: Aug 17, 2004
 * Time: 11:02:11 PM
 * To change this template use File | Settings | File Templates.
 */
public class TriangleDataModel
        implements SortDataModel

{
    private boolean inverted;

    public TriangleDataModel(boolean inverted)
    {
        this.inverted = inverted;
    }

    public int[] fill(int length)
    {
        int[] array = new int[length];
        final int m = length / 2;
        for (int i = 0; i < m; i++) {
            if (inverted) {
                array[i] = length - i * 2 - 1;
            }
            else {
                array[i] = i * 2 + 1;
            }
            array[length - i - 1] = array[i] + 1;
        }
        return array;
    }

    public String toString()
    {
        return inverted ? "Inverted Triangle" : "Triangle";
    }

}
